<?php
/*
*	created by cbq in 2017.02.08
*	系统日志模型类
*/
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Model extends CI_Model {
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }
    public function com_where($where){
        if(empty($where)){return false;}
        foreach($where as $k=>$v){
            if($v[0]=='in'){
                if(is_string($v[1])){$v[1]=explode(',',$v[1]);}
                if(isset($v[2]) && $v[2]=='||'){
                  $this->db->or_where_in($k,$v[1]);
                }else{
                  $this->db->where_in($k,$v[1]);
                }
                continue;
            }elseif($v[0]=='notin'){
                if(is_string($v[1])){$v[1]=explode(',',$v[1]);}
                if(isset($v[2]) && $v[2]=='||'){
                  $this->db->or_where_not_in($k,$v[1]);
                }else{
                    $this->db->where_not_in($k,$v[1]);
                }
                continue;
            }elseif($v[0]=='like'){
              if(isset($v[2]) && $v[2]=='||'){
                  $this->db->or_like($k,$v[1]);
              }else{
                  $this->db->like($k,$v[1]);
              }
              continue;
            }elseif($v[0]=='notlike'){
              if(isset($v[2]) && $v[2]=='||'){
                  $this->db->or_not_like($k,$v[1]);
              }else{
                  $this->db->not_like($k,$v[1]);
              }
              continue;
            }elseif($v[0]=='between'){
                if(isset($v[3]) && $v[3]=='||'){
                    $this->db->or_where($k." between ".$v[1]." and ".$v[2]);
                }else{
                    $betwen=$k." between $v[1] and ".$v[2];
                    $this->db->where($betwen);
                }
                continue;
            }elseif($v[0]=="notbetween"){
                if(isset($v[3]) && $v[3]=='||'){
                    $this->db->or_where($k." not between ".$v[1]." and ".$v[2]);
                }else{
                    $this->db->where($k." not between ".$v[1]." and ".$v[2]);
                }
                continue;
            }else{
                $x=$k." ".$v[0];
                if(isset($v[2]) && $v[2]=='||'){
                    $this->db->or_where($x,$v[1]);
                }else{
                  $this->db->where($x,$v[1]);
                }
                continue;
            }
        }
    }
  	/**
  	* 分页查询
  	*/
  	public function page_show($pagesize=10,$pagecount){
  		//分页
  		if(isset($_GET)){
  			$search_arr=$_GET;
  			unset($search_arr['page']);
  			$search_str=http_build_query($search_arr);
  		}
      	$this->ctl=$this->router->fetch_class();
  		$this->method = $this->router->fetch_method();
  		$preurl=base_url().$this->ctl."/".$this->method;
  		if($search_str){//判断是否有其他参数
  			$web_url=$preurl.'?'.$search_str.'&page=';
  		}else{
  			$web_url=$preurl.'?page=';
  		}
  		$this->page=mcms_cmsclass('Page');
  		$this->page->var_url($web_url);
  		$this->page->init($pagesize,$pagecount);
  		$this->page->setConfig('a_pre',"上一页");
  		$this->page->setConfig('a_nex',"下一页");
  		$this->page->setConfig('a_total','');
  		$pageshow=$this->page->show_page();
  		return $pageshow;
  	}
  	/**
  	* ajaxpage
  	* 注意其他参数查询
  	* @param undefined $pagesize每页显示条数
  	* @param undefined $pagecount 总条数
  	*
  	* @return
  	*/
  	public function pageajax_show($pagesize=10,$pagecount){
      $this->page=load_class('Pageajax');
  		$this->page->init($pagesize,$pagecount);
  		$this->page->setConfig('a_pre',"上一页");
  		$this->page->setConfig('a_nex',"下一页");
  		$this->page->setConfig('a_total','');
  		$pageshow=$this->page->show_page();
  		return $pageshow;
  	}
}
?>
